VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmConsultaTransacciones 
   BackColor       =   &H80000013&
   Caption         =   "Consulta de Transacciones"
   ClientHeight    =   8490
   ClientLeft      =   60
   ClientTop       =   360
   ClientWidth     =   13155
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   8490
   ScaleWidth      =   13155
   Begin MSComDlg.CommonDialog cd 
      Left            =   10560
      Top             =   7680
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdExportarExcel 
      Height          =   855
      Left            =   11040
      Picture         =   "frmConsultaTransacciones.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   15
      Top             =   7440
      Width           =   1095
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "Ce&rrar"
      Height          =   855
      Left            =   360
      Picture         =   "frmConsultaTransacciones.frx":09DC
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   7440
      Width           =   1455
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H80000013&
      Caption         =   "Filtros"
      Height          =   1455
      Left            =   120
      TabIndex        =   6
      Top             =   120
      Width           =   12855
      Begin VB.ComboBox cboOrden 
         Height          =   315
         ItemData        =   "frmConsultaTransacciones.frx":0CE6
         Left            =   9120
         List            =   "frmConsultaTransacciones.frx":0CFC
         Style           =   2  'Dropdown List
         TabIndex        =   13
         Top             =   480
         Width           =   2055
      End
      Begin VB.CheckBox chkFactura 
         BackColor       =   &H80000013&
         Caption         =   "Facturas"
         Height          =   375
         Left            =   120
         TabIndex        =   12
         Top             =   240
         Width           =   975
      End
      Begin VB.CheckBox chkNotaDebito 
         BackColor       =   &H80000013&
         Caption         =   "Notas de Debito"
         Height          =   255
         Left            =   120
         TabIndex        =   11
         Top             =   840
         Width           =   1695
      End
      Begin VB.CheckBox chkNotaCredito 
         BackColor       =   &H80000013&
         Caption         =   "Notas de Credito"
         Height          =   255
         Left            =   120
         TabIndex        =   10
         Top             =   1080
         Width           =   1575
      End
      Begin VB.CheckBox chkRecibos 
         BackColor       =   &H80000013&
         Caption         =   "Recibos"
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   600
         Width           =   975
      End
      Begin VB.CommandButton cmdBuscar 
         Height          =   855
         Left            =   11400
         Picture         =   "frmConsultaTransacciones.frx":0D30
         Style           =   1  'Graphical
         TabIndex        =   3
         Top             =   360
         Width           =   1215
      End
      Begin CtaCte.txtCliente txtCliente 
         Height          =   975
         Left            =   1800
         TabIndex        =   0
         Top             =   240
         Width           =   5535
         _extentx        =   9763
         _extenty        =   1720
      End
      Begin MSComCtl2.DTPicker dtpHasta 
         Height          =   375
         Left            =   7440
         TabIndex        =   2
         Top             =   960
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   661
         _Version        =   393216
         Format          =   60030977
         CurrentDate     =   39682
      End
      Begin MSComCtl2.DTPicker dtpDesde 
         Height          =   375
         Left            =   7440
         TabIndex        =   1
         Top             =   360
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   661
         _Version        =   393216
         Format          =   60030977
         CurrentDate     =   39682
      End
      Begin VB.Label Label3 
         BackColor       =   &H80000013&
         Caption         =   "Orden"
         Height          =   255
         Left            =   9120
         TabIndex        =   14
         Top             =   240
         Width           =   1335
      End
      Begin VB.Label Label1 
         BackColor       =   &H80000013&
         Caption         =   "Desde"
         Height          =   255
         Left            =   7440
         TabIndex        =   8
         Top             =   120
         Width           =   1215
      End
      Begin VB.Label Label2 
         BackColor       =   &H80000013&
         Caption         =   "Hasta"
         Height          =   255
         Left            =   7440
         TabIndex        =   7
         Top             =   720
         Width           =   1575
      End
   End
   Begin MSFlexGridLib.MSFlexGrid lvConsulta 
      Height          =   5535
      Left            =   120
      TabIndex        =   4
      Top             =   1680
      Width           =   12855
      _ExtentX        =   22675
      _ExtentY        =   9763
      _Version        =   393216
      FixedCols       =   0
      Redraw          =   -1  'True
      AllowBigSelection=   0   'False
      FocusRect       =   0
      SelectionMode   =   1
      AllowUserResizing=   3
   End
End
Attribute VB_Name = "frmConsultaTransacciones"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim sql, sCliente As String
Dim bPrimeraVez As Boolean

Private Sub cboOrden_Click()
If Not bPrimeraVez Then cmdBuscar_Click
End Sub

Private Sub cmdBuscar_Click()
bPrimeraVez = False
lvConsulta.Clear
lvConsulta.Rows = 1
titulos
sCliente = ""
If txtCliente.getTodos = 0 And txtCliente.text = "" Then
    MsgBox "Ingrese Cliente o seleccione Todos", vbOKOnly, "Error"
Else
If txtCliente.getTodos = 0 Then sCliente = " AND cliente = " & Str(txtCliente.text)

sql = " select 'Factura' tipo, RIGHT('0000' + CAST(fac_puesto AS VARCHAR), 4) + '-' + RIGHT('00000000' + cast(fac_numero AS varchar(8)), 8)  numero, fac_fecha fecha, nombreorazonsocial clientes, cuit, fac_monto monto, ' ' concepto, ope_nombre operador, c.id_cliente cliente " _
    & " into #temporales from factura f, cliente c, operadores o " _
    & " where f.id_cliente = c.id_cliente and f.ope_codigo = o.ope_codigo AND 1 = " & Str(chkFactura.Value) _
    & " UNION ALL select 'Recibo', CAST(rec_numero AS VARCHAR), rec_fecha, nombreorazonsocial, cuit, rec_importe, rec_concepto, ope_nombre, c.id_cliente " _
    & " from recibo r, cliente c, operadores o " _
    & " where r.id_cliente = c.id_cliente and r.ope_codigo = o.ope_codigo  AND 1 = " & Str(chkRecibos.Value) _
    & " UNION ALL select 'N Credito', CAST(cre_numero AS VARCHAR) , cre_fecha, nombreorazonsocial, cuit, cre_importe, cre_concepto, ope_nombre, c.id_cliente " _
    & " from notacredito f, cliente c, operadores o " _
    & " where f.id_cliente = c.id_cliente and f.ope_codigo = o.ope_codigo  AND 1 = " & Str(chkNotaCredito.Value) _
    & " UNION ALL select 'N Debito', CAST(deb_numero AS VARCHAR), deb_fecha, nombreorazonsocial, cuit, deb_importe, deb_concepto, ope_nombre, c.id_cliente " _
    & " from notadebito f, cliente c, operadores o " _
    & " where f.id_cliente = c.id_cliente and f.ope_codigo = o.ope_codigo  AND 1 = " & Str(chkNotaDebito.Value) _

cn.BeginTrans
cn.Execute sql
ConsultaSql " SELECT * FROM #temporales " _
    & " WHERE fecha >= '" & dtpDesde.Value & "'" _
    & " AND fecha <= '" & dtpHasta.Value & "'" _
    & sCliente & " ORDER BY " & cboOrden.text
If Not rs.RecordCount = 0 Then

rs.MoveFirst
While (Not rs.EOF)
    stringitem = rs.Fields(0) & Chr(9) & rs.Fields(1) & Chr(9) & Str(rs.Fields(2)) & Chr(9) & rs.Fields(3) & Chr(9) & rs.Fields(4) & Chr(9) & Str(rs.Fields(5)) & Chr(9) & rs.Fields(6) & Chr(9) & rs.Fields(7)
    lvConsulta.AddItem stringitem
    rs.MoveNext
Wend
End If
cn.RollbackTrans
End If
End Sub

Private Sub cmdExportarExcel_Click()
    cd.FileName = ""
    cd.Filter = "Excel File(*.xls)|*.xls|Text File (*.txt)|*.txt"
    cd.FilterIndex = 1
    cd.ShowSave
    If cd.FileName <> "" Then
        Exportar_Excel cd.FileName, lvConsulta
        MsgBox "Archivo generado en: " & cd.FileName, vbInformation + vbOKOnly, "Exportar a excel"
    End If
End Sub

Private Sub cmdSalir_Click()
Unload Me
End Sub



Private Sub Form_Load()
Me.Height = 8910
Me.Width = 13110
txtCliente.mostrarTodos True
chkFactura.Value = 1
chkNotaCredito.Value = 1
chkNotaDebito.Value = 1
chkRecibos.Value = 1
txtCliente.setTodos True
lvConsulta.Cols = 8
titulos
bPrimeraVez = True
cboOrden.ListIndex = 0
dtpDesde.Value = Date - 30
dtpHasta.Value = Date

End Sub
Private Sub titulos()
lvConsulta.TextMatrix(0, 0) = "Tipo"
lvConsulta.ColAlignment(0) = flexAlignLeftCenter
lvConsulta.TextMatrix(0, 1) = "Numero"
lvConsulta.ColWidth(1) = 1200
lvConsulta.ColAlignment(1) = flexAlignRightCenter
lvConsulta.TextMatrix(0, 2) = "Fecha"
lvConsulta.ColAlignment(2) = flexAlignLeftCenter
lvConsulta.TextMatrix(0, 3) = "Cliente"
lvConsulta.ColWidth(3) = 3500
lvConsulta.ColAlignment(3) = flexAlignLeftCenter
lvConsulta.TextMatrix(0, 4) = "CUIT"
lvConsulta.ColWidth(4) = 1200
lvConsulta.ColAlignment(4) = flexAlignLeftCenter
lvConsulta.TextMatrix(0, 5) = "Monto"
lvConsulta.ColAlignment(5) = flexAlignRightCenter
lvConsulta.TextMatrix(0, 6) = "Concepto"
lvConsulta.ColWidth(6) = 3500
lvConsulta.ColAlignment(6) = flexAlignLeftCenter
lvConsulta.TextMatrix(0, 7) = "Operador"
lvConsulta.ColAlignment(7) = flexAlignLeftCenter
lvConsulta.ColWidth(7) = 1700
End Sub

Private Sub lvConsulta_DblClick()
If lvConsulta.TextMatrix(lvConsulta.Row, 0) = "Factura" Then
    frmFacturaDetalle.Show
    frmFacturaDetalle.setNumero lvConsulta.TextMatrix(lvConsulta.Row, 1)
ElseIf lvConsulta.TextMatrix(lvConsulta.Row, 0) = "Recibo" Then
    frmRecibo.Show
    frmRecibo.setNumero lvConsulta.TextMatrix(lvConsulta.Row, 1)
ElseIf lvConsulta.TextMatrix(lvConsulta.Row, 0) = "N Credito" Then
    frmNotaCredito.Show
    frmNotaCredito.setNumero lvConsulta.TextMatrix(lvConsulta.Row, 1)
ElseIf lvConsulta.TextMatrix(lvConsulta.Row, 0) = "N Debito" Then
    frmNotaDebito.Show
    frmNotaDebito.setNumero lvConsulta.TextMatrix(lvConsulta.Row, 1)
End If
End Sub
